#!/bin/bash
cd ~/app-root/data/temp/tool/
i="ithome.txt"
if ! grep -q "$(grep "^title" $i|awk -F ': ' '{print $2}')：" ~/app-root/repo/log/sign.log; then
    echo "$(grep "^title" $i|awk -F ': ' '{print $2}')：从未签到" >> ~/app-root/repo/log/sign.log
elif grep -q "$(grep "^title" $i|awk -F ': ' '{print $2}')：$(date -d "8 hour" -u "+%Y年%m月%d日")" ~/app-root/repo/log/sign.log; then
    exit
fi
s=$(grep -o "^runtimes[0-9]" $i|grep -o '[0-9]'|tail -1)
for((m=1;m<=$s;m++)); do
    n=$(grep "^runtimes${m}" $i|awk -F ': ' '{print $2}')
    for((r=1;r<=$n;r++)); do
        curl -s "https://my.ruanmei.com/api/task.asmx/DoTask?userHash=$(grep '^Cookie' $i|awk -F ': ' '{print $2}')&strTaskID=$(grep "^runtasks${m}" $i|awk -F ': ' '{print $2}')" >>log.txt
        if [ "$r" -lt "$n" ]; then sleep 3;fi
    done
done
if grep -E -q 'true|false' log.txt; then
    sed -i "/$(grep "^title" $i|awk -F ': ' '{print $2}')：/s#：.*#：$(date -d "8 hour" -u "+%Y年%m月%d日 %H:%M")#" ~/app-root/repo/log/sign.log
fi
rm -f log.txt
